package com.Mybatis3源码深度解析.c3;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.apache.ibatis.reflection.factory.ObjectFactory;
import org.junit.Test;

public class ObjectFactoryExample {

	private static class Order {
        String orderNo;
        String goodsName;
		public String getOrderNo() {
			return orderNo;
		}
		public void setOrderNo(String orderNo) {
			this.orderNo = orderNo;
		}
		public String getGoodsName() {
			return goodsName;
		}
		public void setGoodsName(String goodsName) {
			this.goodsName = goodsName;
		}
		public Order(String orderNo, String goodsName) {
			super();
			this.orderNo = orderNo;
			this.goodsName = goodsName;
		}
		public Order() {
			super();
		}

    }

    @Test
    public void testObjectFactory() {
        ObjectFactory objectFactory = new DefaultObjectFactory();
        List<Integer> list = objectFactory.create(List.class);
        Map<String,String> map = objectFactory.create(Map.class);
        list.addAll(Arrays.asList(1, 2, 3));
        map.put("test", "test");
        System.out.println(list);
        System.out.println(map);

        List<Class<?>> constructorArgTypes = new ArrayList<>();
        constructorArgTypes.add(String.class);
        constructorArgTypes.add(String.class);
        List<Object> constructorArgs = new ArrayList<>();
        constructorArgs.add("123");
        constructorArgs.add("xxx");
        Order o = objectFactory.create(Order.class, constructorArgTypes, constructorArgs);
    }
}
